Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@ethersproject/abstract-provider
Advanced tools
An Abstract Class for describing an Ethereum Provider for ethers.
@ethersproject/abstract-provider is a part of the ethers.js library, which provides a collection of utilities for interacting with the Ethereum blockchain. This specific package defines the abstract interface for a provider, which is responsible for communicating with the Ethereum network. It includes methods for querying the blockchain, sending transactions, and listening for events.
Querying the Blockchain
This feature allows you to query the current block number from the Ethereum blockchain using a JSON-RPC provider.
const { JsonRpcProvider } = require('@ethersproject/providers');
const provider = new JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
async function getBlockNumber() {
const blockNumber = await provider.getBlockNumber();
console.log('Current block number:', blockNumber);
}
getBlockNumber();
Sending Transactions
This feature demonstrates how to send a transaction on the Ethereum network using a wallet connected to a provider.
const { JsonRpcProvider } = require('@ethersproject/providers');
const { Wallet } = require('@ethersproject/wallet');
const provider = new JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider);
async function sendTransaction() {
const tx = {
to: '0xRecipientAddress',
value: ethers.utils.parseEther('0.01')
};
const transactionResponse = await wallet.sendTransaction(tx);
console.log('Transaction hash:', transactionResponse.hash);
}
sendTransaction();
Listening for Events
This feature shows how to listen for new blocks being mined on the Ethereum blockchain.
const { JsonRpcProvider } = require('@ethersproject/providers');
const provider = new JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
provider.on('block', (blockNumber) => {
console.log('New block mined:', blockNumber);
});
web3.js is a popular library for interacting with the Ethereum blockchain. It provides similar functionalities to @ethersproject/abstract-provider, such as querying the blockchain, sending transactions, and listening for events. However, web3.js has a larger footprint and can be more complex to use compared to ethers.js.
ethjs is a lightweight JavaScript library for interacting with the Ethereum blockchain. It provides similar functionalities to @ethersproject/abstract-provider but is designed to be minimalistic and easy to use. It is a good alternative for developers looking for a smaller library.
This sub-module is part of the ethers project.
It is responsible for defining the common interface for a Provider, which in ethers differs quite substantially from Web3.js.
A Provider is an abstraction of non-account-based operations on a blockchain and is generally not directly involved in signing transaction or data.
For signing, see the Abstract Signer or Wallet sub-modules.
For more information, see the documentation.
Most users will prefer to use the umbrella package, but for those with more specific needs, individual components can be imported.
const {
Provider,
ForkEvent,
BlockForkEvent,
TransactionForkEvent,
TransactionOrderForkEvent,
// Types
BlockTag,
Block,
BlockWithTransactions,
TransactionRequest,
TransactionResponse,
TransactionReceipt,
Log,
EventFilter,
Filter,
FilterByBlockHash,
EventType,
Listener
} = require("@ethersproject/abstract-provider");
MIT License
FAQs
An Abstract Class for describing an Ethereum Provider for ethers.
The npm package @ethersproject/abstract-provider receives a total of 665,375 weekly downloads. As such, @ethersproject/abstract-provider popularity was classified as popular.
We found that @ethersproject/abstract-provider demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.